package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.tonbing.config.*;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.pb.activity.TonBingProto;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.utils.date.DateHelper;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class TonBingPb {

    public static TonBingProto.TonBingSyncConfigRespMsg.Builder parseTonBingSyncConfigRespMsg(TonBingConfig config, String language) {
        TonBingProto.TonBingSyncConfigRespMsg.Builder builder = TonBingProto.TonBingSyncConfigRespMsg.newBuilder();
        for (TonBingBuffTypeConfig buffTypeConfig : config.getBuffTypeConfigMap().values()) {
            builder.addBuffTypeConfig(TonBingPb.parseTonBingBuffTypeConfigMsg(buffTypeConfig, language));
        }

        for(int warType : config.getCityTypeConfigMap().keySet()){
            for (TonBingCityTypeConfig cityTypeConfig : config.getCityTypeConfigMap().get(warType).values()) {
                builder.addCityTypeConfig(TonBingPb.parseTonBingCityTypeConfigMsg(cityTypeConfig, language));
            }
        }
        for(int warType : config.getCityConfigMap().keySet()){
            for (TonBingCityConfig cityConfig : config.getCityConfigMap().get(warType).values()) {
                builder.addCityConfig(TonBingPb.parseTonBingCityConfigMsg(cityConfig, language));
            }
        }

        for (TonBingNpcEventConfig npcEventConfig : config.getNpcEventConfigMap().values()) {
            builder.addNpcEventConfig(TonBingPb.parseTonBingNpcEventConfigMsg(npcEventConfig));
        }
        for (Map<Integer, TonBingTitleConfig> titleConfigMap : config.getTitleConfigMap().values()) {
            for(TonBingTitleConfig titleConfig : titleConfigMap.values()){
                builder.addTitleConfig(TonBingPb.parseTonBingTitleConfigMsg(titleConfig, language));
            }
        }
        return builder;
    }

    public static TonBingProto.TonBingBuffTypeConfigMsg.Builder parseTonBingBuffTypeConfigMsg(TonBingBuffTypeConfig config, String language) {
        TonBingProto.TonBingBuffTypeConfigMsg.Builder builder = TonBingProto.TonBingBuffTypeConfigMsg.newBuilder();
        builder.setId(config.getId());
        builder.setBuffType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(config.getDesc(), language));
        builder.setBuffEffect(config.getBuffEffect());
        builder.setContinueTime((int) (config.getContinueTime() / DateHelper.HOUR_MILLIONS));
        return builder;
    }

    public static TonBingProto.TonBingCityTypeConfigMsg.Builder parseTonBingCityTypeConfigMsg(TonBingCityTypeConfig config, String language) {
        TonBingProto.TonBingCityTypeConfigMsg.Builder builder = TonBingProto.TonBingCityTypeConfigMsg.newBuilder();
        builder.setCityType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setFoodProduction(config.getFoodProduction());
        builder.setTeamNum(config.getTeamNum());
        builder.setSoldierNum(config.getSoldierNum());
        builder.setAddition(config.getAddition());
        builder.setBuffEffect(String.valueOf(config.getBuffEffect()));
        builder.setCampScore(config.getCampPoint());
        builder.setExtraTeamNum(config.getExtraTeamNum());
        builder.setWarType(config.getWarType());
        return builder;
    }

    public static TonBingProto.TonBingCityConfigMsg.Builder parseTonBingCityConfigMsg(TonBingCityConfig config, String language) {
        TonBingProto.TonBingCityConfigMsg.Builder builder = TonBingProto.TonBingCityConfigMsg.newBuilder();
        builder.setCityId(config.getId());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setMapType(config.getMapType());
        builder.setCityType(config.getType());
        builder.setInitialCamp(config.getInitialCamp());
        builder.setShowType(config.getShowType());
        builder.setSpecialAddition(config.getSpecialAddition());
        builder.setWarType(config.getWarType());
        return builder;
    }

    public static TonBingProto.TonBingNpcEventConfigMsg.Builder parseTonBingNpcEventConfigMsg(TonBingNpcEventConfig config) {
        TonBingProto.TonBingNpcEventConfigMsg.Builder builder = TonBingProto.TonBingNpcEventConfigMsg.newBuilder();
        builder.setEventId(config.getId());
        builder.setEventType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setRewards(config.getRewards());
        return builder;
    }


    public static TonBingProto.TonBingTitleConfigMsg.Builder parseTonBingTitleConfigMsg(TonBingTitleConfig config, String language) {
        TonBingProto.TonBingTitleConfigMsg.Builder builder = TonBingProto.TonBingTitleConfigMsg.newBuilder();
        builder.setTitleId(config.getId());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setType(config.getType());
        builder.setEffect(config.getEffect());
        builder.setRewards(config.getRewards());
        builder.setCampId(config.getCampId());
        return builder;
    }

    /**
     * 获取战力同步门客列表
     */
    public static List<TonBingProto.TonBingPatronsTempMsg> parseTonBingPatronsListMsg(List<UserPatrons> userPatronsList) {
        List<TonBingProto.TonBingPatronsTempMsg> list = new ArrayList<>();
        for (UserPatrons userPatrons : userPatronsList) {
            TonBingProto.TonBingPatronsTempMsg.Builder tempBuilder = TonBingProto.TonBingPatronsTempMsg.newBuilder();
            tempBuilder.setId(userPatrons.getPatronsId());
            tempBuilder.setSkin(userPatrons.getSkinId());
            tempBuilder.setAbility(userPatrons.getAbility().longValue());
            list.add(tempBuilder.build());
        }
        return list;
    }

}
